#include "common.h"


int main()
{
    //打开管道
    int fd = open(FILE_NAME,O_WRONLY);
    if(fd < 0)
    {
        perror("open");
        return 1;
    }
    //打开file.txt文件
    int fdin = open("file.txt",O_RDONLY);
    if(fdin < 0)
    {
        perror("open");
        return 3;
    }
    //写入数据
    char msg[128];
    while(1)
    {
        msg[0] = '\0';
        
        size_t size = read(fdin,msg,sizeof(msg));
        if(size > 0)
        {
            msg[size - 1] = '\0';
            //信息写入管道
            write(fd,msg,size);
        }
        else if(size == 0)
        {
            printf("read end of file\n");
            break;
        }
        else
        {
            printf("read error\n");
            break;
        }
    }
    close(fdin);
    close(fd);
    return 0;
}